// Copyright (c) Huoty, All rights reserved
// Author: Huoty <sudohuoty@163.com>
// CreateTime: 2021-03-03 13:32:17

package main

import "fmt"
import "sync"

func main() {
    var scene sync.Map
    // 将键值对保存到sync.Map
    scene.Store("greece", 97)
    scene.Store("london", 100)
    scene.Store("egypt", 200)

    tmap := map[string]string{}
    tmap["hello"] = "hello world"
    scene.Store("hello", tmap)

    // 从sync.Map中根据键取值
    fmt.Println("------------------")
    fmt.Println(scene.Load("london"))
    fmt.Println(scene.Load("hello"))
    // 根据键删除对应的键值对
    scene.Delete("london")
    // 遍历所有sync.Map中的键值对
    scene.Range(func(k, v interface{}) bool {
        fmt.Println("iterate:", k, v)
        return true
    })
}
